package 剑指offer;

/**
 * Created by yang on 2016/8/24.
 *  {1,3,5},{2,4,6} ---> {1,2,3,4,5,6}
 * 输入两个单调递增的链表，
 * 输出两个链表合成后的链表，
 * 当然我们需要合成后的链表满足单调不减规则。
 */
public class MergeTwoListNodeOfOrder {

    public ListNode Merge(ListNode list1,ListNode list2) {

        ListNode nodeOfmerge = null;
        if (list1 == null) {
            return list2;
        }else if (list2 == null){
            return list1;
        }

        if (list1.val < list2.val) {
            nodeOfmerge = list1;
            nodeOfmerge.next = Merge(list1.next , list2);
        }else{
            nodeOfmerge = list2;
            nodeOfmerge.next = Merge(list1 , list2.next);
        }

        return nodeOfmerge;
    }
}
